home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
comm
/
bbs_tee.zip
/
BBS.C
< prev
next >
Wrap
Text File
|
1987-06-10
|
16KB
|
851 lines
#include "stdio.h"
#include "ctype.h"
#include "dos.h" /* mscv4.0 (others, you're on your own!) */
#undef tolower /* we want function, not macro from ctype.h */
#define FAST static
static int left_flag, do_padding, num1, num2;
static char outbuf[32], *sp_ptr, pad_character;
static void outs(int (*)(int),char *), outnum(int (*)(int), long, long);
static int getnum(char **);
union REGS srv,rrv; /*
** this uses the ansiterm.c routines that
** are provided with Pro-Yam
*/
struct {
char name[26];
char pass[11];
int timeson;
} user;
struct {
int users;
int last_user;
char spare[35];
} user_hdr;
struct {
char to[26];
int mnum;
} msg;
struct {
int nxt_mnum;
int msgs;
char spare[24];
} msg_hdr;
int mail;
int local;
int pers;
int usrs;
int msgs;
int urec;
char uname[26],inpbuf[128];
FILE *ufd;
FILE *mfd;
/* expects: first last 0 0
** | | |
** name of user / | |
** signed on = 1/ |
** local = 1/
**
** above can be achieved through:
**
** in challeng.t after getting the user's name and confirmation
** (the name MUST be limited to 25 characters plus a NULL or you will
** have to change the structs above etc.)
** add the line: obey "!~bbs %remote 0 0"
**
** in phones.t add the line: set bbs "~bbs %remote 1 0"
**
** to run locally enter: bbs <first> <last> 0 1
** or: bbs <first> <last> 1 1
** where <first> is your first name and <last> is your last name
*/
main(argc,argv)int argc;
char **argv;
{
int i;
if(argc<5) {
sendf("\nArg error (%d, %s %s %s %s)\n",argc,argv[1],argv[2],argv[3],argv[4]);
sendf("\nTell my boss!\n");
exit(1);
}
mail=atoi(argv[3]);
local=atoi(argv[4]);
strlwr(argv[1]);
strlwr(argv[2]);
argv[1][0]=toupper(argv[1][0]);
argv[2][0]=toupper(argv[2][0]);
sprintf(uname,"%s %s",argv[1],argv[2]);
pers=FALSE;
if(mail)
goto do_mail;
sendf("\n\n\n\nRemote Pro-Yam Signon Utility v1.00 (c)1987 Simon J. Ewins\n");
if((ufd=fopen("\\rem\\users.bbs","r+"))==0) {
ufd=fopen("\\rem\\users.bbs","w+");
if(!ufd) {
sendf("\nCan't make users file, tell my boss!\n");
exit(1);
}
user_hdr.users=0;
r_put(ufd,0,sizeof(user_hdr),&user_hdr);
}
r_get(ufd,0,sizeof(user_hdr),&user_hdr);
usrs=user_hdr.users;
sendf("\nSearching %d users.\n",usrs);
if(usrs==0) {
i=1;
goto not_found;
}
for(i=1;i<=usrs;++i) {
sendf("\r# %d ",i);
r_get(ufd,i,sizeof(user),&user);
if(!strcmp(user.name,uname))
goto found;
}
not_found:
sendf("\nCan't find %s. Please choose a password: ",uname);
get_line(10,TRUE,inpbuf);
if(!strlen(inpbuf))
goto not_found;
strcpy(user.name,uname);
strcpy(user.pass,inpbuf);
user.timeson=0;
r_put(ufd,i,sizeof(user),&user);
++user_hdr.users;
user_hdr.last_user=i;
++usrs;
r_put(ufd,0,sizeof(user_hdr),&user_hdr);
fflush(ufd);
sendf("\nRemember it and be careful because");
found:
urec=i;
sendf("\nUpper and Lower case count!\nPassword: ");
get_line(10,FALSE,inpbuf);
if(!strlen(inpbuf) || strcmp(user.pass,inpbuf)) {
sendf(" <== wrong!");
goto found;
}
++user.timeson;
r_put(ufd,urec,sizeof(user),&user);
fclose(ufd);
sendf("\nLogin: %d",user.timeson);
sendf("\nChecking for mail.\n");
if((mfd=fopen("\\rem\\msgs.bbs","r+"))==0) {
mfd=fopen("\\rem\\msgs.bbs","w+");
if(!mfd) {
sendf("\nCan't make msg file, tell my boss!\n");
exit(1);
}
msg_hdr.nxt_mnum=0;
msg_hdr.msgs=0;
r_put(mfd,0,sizeof(msg_hdr),&msg_hdr);
}
r_get(mfd,0,sizeof(msg_hdr),&msg_hdr);
if(msg_hdr.msgs==0)
goto mnot_found;
for(i=1;i<=msg_hdr.msgs;++i) {
sendf("\r...\b\b\b");
r_get(mfd,i,sizeof(msg),&msg);
if(!strcmp(msg.to,uname))
goto mfound;
}
mnot_found:
sendf("\nCan't find any for you.\n");
fclose(mfd);
exit(0);
mfound:
sendf("\nThere is mail for you...");
pers=TRUE;
fclose(mfd);
do_mail:
if((mfd=fopen("\\rem\\msgs.bbs","r+"))==0) {
mfd=fopen("\\rem\\msgs.bbs","w+");
if(!mfd) {
sendf("\nCan't create the msg file! Tell my boss.");
exit(1);
}
msg_hdr.nxt_mnum=0;
msg_hdr.msgs=0;
r_put(mfd,0,sizeof(msg_hdr),&msg_hdr);
}
r_get(mfd,0,sizeof(msg_hdr),&msg_hdr);
mloop:
switch(tolower(menu())) {
int sho;
case 'q':
goto done;
case 'a':
for(i=1,sho=0;i<=msg_hdr.msgs;++i) {
if(getchr()==24)
break;
sendf("...\b\b\b");
r_get(mfd,i,sizeof(msg),&msg);
if(!strcmp(msg.to,"All")) {
++sho;
if(shomsg(msg.mnum)=='q')
break;
}
}
sendf("\nFound %d public message(s), [Press any key]",sho);
wtchr();
break;
case 'p':
for(i=1,sho=0;i<=msg_hdr.msgs;++i) {
if(getchr()==24)
break;
sendf("...\b\b\b");
r_get(mfd,i,sizeof(msg),&msg);
if(!strcmp(msg.to,uname) || local) {
++sho;
if(shomsg(msg.mnum)=='q')
break;
}
}
sendf("\nFound %d message(s) for you, [Press any key]",sho);
wtchr();
break;
case 'u':
users();
break;
case 'e':
enter();
break;
case 's':
if(local)
sysop();
break;
}
goto mloop;
done:
if(pers) {
sendf("\nDeleting personal messages.\n");
for(i=1;i<=msg_hdr.msgs;++i) {
sendf("...\b\b\b");
r_get(mfd,i,sizeof(msg),&msg);
if(!strcmp(msg.to,uname)) {
msg.to[0]=NULL;
r_put(mfd,i,sizeof(msg),&msg);
sprintf(inpbuf,"\\rem\\%05d.msg",msg.mnum);
unlink(inpbuf);
}
}
}
fclose(mfd);
exit(0);
}
menu()
{
sendf("\n\n\n\nRemote Pro-Yam Mail Utility v1.00 (c)1987 Simon J. Ewins\n\n");
sendf("Select: A - Read all public messages\n");
sendf(" P - Read your personal messages\n");
sendf(" U - Display users list\n");
sendf(" E - Enter a message\n");
sendf(" Q - Quit");
if(pers)
sendf(" and delete personal messages");
putchr('\n');
sendf("?> ");
return(wtchr());
}
shomsg(n)
int n;
{
FILE *tfd;
int c,ch;
sendf("\nPress ^X to quit:\n\n");
sprintf(inpbuf,"\\rem\\%05d.msg",msg.mnum);
tfd=fopen(inpbuf,"r");
if(!tfd) {
sendf("\nHmmm, couldn't open that one!");
return;
}
while((c=fgetc(tfd))!=EOF) {
if(getchr()==19)
wtchr();
if(c==1) {
sendf("R)ead, S)kip, Q)uit: ");
ch=tolower(wtchr());
switch(ch) {
case 'r':
case '\r':
sendf("\r \r");
continue;
case 'q':
case 's':
goto done;
}
}
putchr(c);
if(getchr()==24)
break;
}
done:
fclose(tfd);
return(ch);
}
enter()
{
char *p,d[9],t[9],*strchr();
char c,message[2049];
int pos,hdr,limit;
FILE *tfd;
get_to:
sendf("\n\nTo: ");
get_line(25,TRUE,inpbuf);
if(!strlen(inpbuf))
return;
strlwr(inpbuf);
if(!strcmp(inpbuf,"sysop")) {
sendf("\nUse 'private' at Yam-Host level to leave comments to Sysop.");
return;
}
if(strcmp(inpbuf,"all")) {
p=strchr(inpbuf,' ');
if(!p) {
sendf("\nNeed first AND last name.");
goto get_to;
}
++p;
*p=toupper(*p);
}
*inpbuf=toupper(*inpbuf);
strcpy(msg.to,inpbuf);
getdte(d,t);
sprintf(message,"From: %s Date: %s Time: %s\n\1\0",uname,d,t);
pos=0;
hdr=strlen(message);
limit=2048-hdr;
p=message+hdr;
sendf("\nEnter your message, (%d characters), ^Z to end:\n",limit);
while(TRUE) {
c=wtchr();
if(c==26)
break;
if(c=='\b' || c==127) {
if(pos<1) {
putchr(7);
continue;
}
putchr('\b');
putchr(' ');
putchr('\b');
*p--=NULL;
--pos;
continue;
}
if(c=='\r') {
if(pos+2>limit) {
putchr(7);
continue;
}
*p++=c;
*p++='\n';
pos+=2;
putchr('\n');
continue;
}
if(pos+1>limit) {
putchr(7);
continue;
}
*p++=c;
++pos;
putchr(c);
}
*p=EOF;
r_get(mfd,0,sizeof(msg_hdr),&msg_hdr);
msg_hdr.msgs++;
msg.mnum=msg_hdr.nxt_mnum++;
r_put(mfd,0,sizeof(msg_hdr),&msg_hdr);
r_put(mfd,msg_hdr.msgs,sizeof(msg),&msg);
fflush(mfd);
sprintf(inpbuf,"\\rem\\%05d.msg",msg.mnum);
tfd=fopen(inpbuf,"w+");
fwrite(message,pos+hdr+1,1,tfd);
fclose(tfd);
}
users()
{
int